package com.ruoyi.web.pojo.dto.warning;

import com.ruoyi.web.utils.influxdb.DeviceData;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.DoubleSummaryStatistics;
import java.util.HashMap;
import java.util.List;

/**
 * @desc  聚合数据
 * @author fwx 2024/2/4 13:42
 **/
@Data
public class AggregatedData {

    public String date;

    public Double max;

    public Double min;
    
    /**
     * @desc  统计某一天数据的最大和最小值
     * @author fwx 2024/2/4 16:01
     **/
    public AggregatedData(List<DeviceData> list,String key) {

        if(CollectionUtils.isEmpty(list)){
            return;
        }

        DoubleSummaryStatistics statistics = list.stream()
                .filter(dd -> dd.getDouble(key) != null)
                .mapToDouble(dd -> dd.getDouble(key)).summaryStatistics();
        this.max = statistics.getMax();
        this.min = statistics.getMin();
        this.date = list.get(0).getDataDateStr();
    }


    @Override
    public String toString() {
        return  "[" + date + ":" + min + "/"+ max + "]" ;
    }

    public static void main(String[] args) {

    }

}
